package com.instwall.callbase.tool;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
 * Created by lk on 17-7-25.
 */

public class ParseUtil {

    /**
     * 叫号信息
     * {"code":"200","message":"成功","body":{"bigTable":0,"smallTable":0,"inTable":0}}
     */
    public static HashMap<String, Integer> parseCallNumMesg(String message) {
        HashMap<String, Integer> hashMap = new HashMap<>();
        try {
            JSONObject jsonObject = new JSONObject(message);
            JSONObject bodyJsonObject = jsonObject.getJSONObject("body");
            hashMap.put("bigTable", bodyJsonObject.getInt("bigTable"));
            hashMap.put("smallTable", bodyJsonObject.getInt("smallTable"));
            hashMap.put("inTable", bodyJsonObject.getInt("bigTable"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return hashMap;
    }

    /**
     * @param message String
     * @return HashMap
     */
//    {"code":"200","message":"成功","body":[{"marketId":"01","prepareOrderList":[[{"agentmemo":"","arrivedStatus":"","callbacks":[{}],"contactname":"测试小妞妞","contactphone":"15011278612","custmemo":"  需要靠垫:是  用户选择了[4人桌-大厅]  包间服务费：0.0","customerid":"","customerlevel":"","deliveryaddressid":"","deliveryagent":"","deliveryfee":0,"deliverytype":"","deposit":0,"dinningtime":"2017-07-25 12:30:00.0","dishprice":266,"distance":0,"haschild":"","hasold":"","haspregnant":"","isPaid":"","isTempOrder":"","markettype":"01","orderid":"S00201122017072513164","ordertype":"2","othertable":"","participantnumber":3,"potbillid":"","potnumber":0,"potstatus":"","prepayprice":50,"recieptdept":"","searchArrivedStatus":[],"serialid":"","sex":"1","status":"01","storeid":"","tableid":"998","tablename":"","timeEnd":"","timeStart":"","totalprice":0,"unarrivedNumber":"","waiterfee":0,"waiternumber":0,"yl":"","yl1":0,"yl2":""},{"agentmemo":"","arrivedStatus":"","callbacks":[{}],"contactname":"测试小妞妞","contactphone":"15011278612","custmemo":"    用户选择了[4人桌-大厅]  包间服务费：0.0","customerid":"","customerlevel":"","deliveryaddressid":"","deliveryagent":"","deliveryfee":0,"deliverytype":"","deposit":0,"dinningtime":"2017-07-25 12:40:00.0","dishprice":216,"distance":0,"haschild":"","hasold":"","haspregnant":"","isPaid":"","isTempOrder":"","markettype":"01","orderid":"S00201122017072513165","ordertype":"2","othertable":"002,015,016","participantnumber":4,"potbillid":"","potnumber":0,"potstatus":"","prepayprice":50,"recieptdept":"","searchArrivedStatus":[],"serialid":"","sex":"1","status":"01","storeid":"","tableid":"998","tablename":"","timeEnd":"","timeStart":"","totalprice":0,"unarrivedNumber":"","waiterfee":0,"waiternumber":0,"yl":"","yl1":0,"yl2":""}],[]]}]}
    public static HashMap<String, String> parseOrderListMesg(String message) {
        HashMap<String, String> hashMap = new HashMap<>();
        try {
            JSONObject jsonObject = new JSONObject(message);
            JSONArray bodyJSONArray = jsonObject.getJSONArray("body");
            JSONObject jsonObject1 = bodyJSONArray.getJSONObject(0);
            JSONArray jsonArray = jsonObject1.getJSONArray("prepareOrderList");
            JSONArray jsonArray1 = jsonArray.getJSONArray(0);
            JSONObject jsonObject2 = jsonArray1.getJSONObject(0);
            if (!jsonObject2.isNull("contactname")) {
                hashMap.put("contactname", jsonObject2.getString("contactname"));
            }
            if (!jsonObject2.isNull("contactphone")) {
                hashMap.put("contactphone", jsonObject2.getString("contactphone"));
            }
            if (!jsonObject2.isNull("participantnumber")) {
                hashMap.put("participantnumber", jsonObject2.getString("participantnumber"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return hashMap;
    }

    //{"rq_dict': {"call_num": {"rq_interval": 10, "rq_url_list": ["http://172.16.149.101:8989/hdl-nph/rs/multiMedia/arrivalNumber"]}},"store_id": "202112"},
    public static HashMap<String, String> parsePartnerConfig(String message) {
        HashMap<String, String> hashMap = new HashMap<>();
        try {
            JSONObject rq_dictJSONObject = new JSONObject(message);
            JSONObject call_num = rq_dictJSONObject.optJSONObject("call_num");

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return hashMap;
    }

}

